// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: LZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_LZSETUP

// Function declarations
reserve function LZSetup_Function93
reserve function LZSetup_Function94
reserve function LZSetup_Function95
reserve function LZSetup_Function96
reserve function LZSetup_Function97
reserve function LZSetup_Function98
reserve function LZSetup_Function99
reserve function LZSetup_Function100
reserve function LZSetup_Function101
reserve function LZSetup_Function102

// Static Values
public value LZSetup_value30 = 0;
public value LZSetup_value29 = 0;

// Tables
public table LZSetup_table25
	2, 2, 1
end table

public table LZSetup_table1
	0xA000000, 0x62C0000, 8, 49, 0, 9, 8, 102, 0, 86, 2, 13, 0, 11, 2, 10, 0, 9, 2, 13, 0, 7, 8, 13, 56, 1, 40, 3, 8, 38, 0, 27, 1, 13, 0, 13, 2, 13, 0, 10, 2, 7, 8, 9, 56, 1, 40, 4, 8, 27, 0, 13, 2, 12, 0, 12, 2, 10, 0, 15, 2, 7, 0, 14, 2, 10, 0, 35, 48, 1, 32, 4, 0, 8, 2, 6, 
end table

function LZSetup_Function93
	stage[arrayPos0].deformationData1 = 1
	arrayPos0++
	stage[arrayPos0].deformationData1 = 1
	arrayPos0++
	stage[arrayPos0].deformationData1 = 2
	arrayPos0++
	stage[arrayPos0].deformationData1 = 2
	arrayPos0++
	stage[arrayPos0].deformationData1 = 3
	arrayPos0++
	stage[arrayPos0].deformationData1 = 3
	arrayPos0++
	stage[arrayPos0].deformationData1 = 3
	arrayPos0++
	stage[arrayPos0].deformationData1 = 3
	arrayPos0++
	stage[arrayPos0].deformationData1 = 2
	arrayPos0++
	stage[arrayPos0].deformationData1 = 2
	arrayPos0++
	stage[arrayPos0].deformationData1 = 1
	arrayPos0++
	stage[arrayPos0].deformationData1 = 1
	arrayPos0++
end function


function LZSetup_Function94
	stage[arrayPos0].deformationData1 = -1
	arrayPos0++
	stage[arrayPos0].deformationData1 = -1
	arrayPos0++
	stage[arrayPos0].deformationData1 = -2
	arrayPos0++
	stage[arrayPos0].deformationData1 = -2
	arrayPos0++
	stage[arrayPos0].deformationData1 = -3
	arrayPos0++
	stage[arrayPos0].deformationData1 = -3
	arrayPos0++
	stage[arrayPos0].deformationData1 = -3
	arrayPos0++
	stage[arrayPos0].deformationData1 = -3
	arrayPos0++
	stage[arrayPos0].deformationData1 = -2
	arrayPos0++
	stage[arrayPos0].deformationData1 = -2
	arrayPos0++
	stage[arrayPos0].deformationData1 = -1
	arrayPos0++
	stage[arrayPos0].deformationData1 = -1
	arrayPos0++
end function


function LZSetup_Function95
	object.value6 = temp1
	object.value6 >>= 16
	object.value7 = temp1
	object.value7 >>= 8
	object.value7 &= 255
	object.value8 = temp1
	object.value8 &= 255
	object.value9 = temp2
	object.value9 >>= 16
	object.value10 = temp2
	object.value10 >>= 8
	object.value10 &= 255
	object.value11 = temp2
	object.value11 &= 255
	if object.value9 == 0
		object.value9 = 1
	end if
	if object.value10 == 0
		object.value10 = 1
	end if
	if object.value11 == 0
		object.value11 = 1
	end if
	object.value6 <<= 8
	object.value7 <<= 8
	object.value8 <<= 8
	object.value6 /= object.value9
	object.value7 /= object.value10
	object.value8 /= object.value11
	if object.value6 == 0
		object.value6 = 256
	end if
	if object.value7 == 0
		object.value7 = 256
	end if
	if object.value8 == 0
		object.value8 = 256
	end if
end function

function LZSetup_Function96
	temp0 = 0
	GetPaletteEntry(1, 2, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
	temp0++
	GetPaletteEntry(1, 3, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
	temp0++
	GetPaletteEntry(1, 4, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
	temp0++
	GetPaletteEntry(1, 5, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
	temp0++
	while temp0 < 64
		GetPaletteEntry(0, 2, temp1)
		GetPaletteEntry(1, 2, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_SonicSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 224
		temp1 /= object.value6
		temp2 *= 224
		temp2 /= object.value7
		temp3 *= 224
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
		temp0++
		GetPaletteEntry(0, 3, temp1)
		GetPaletteEntry(1, 3, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_SonicSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 232
		temp1 /= object.value6
		temp2 *= 232
		temp2 /= object.value7
		temp3 *= 232
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
		temp0++
		GetPaletteEntry(0, 4, temp1)
		GetPaletteEntry(1, 4, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_SonicSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 244
		temp1 /= object.value6
		temp2 *= 244
		temp2 /= object.value7
		temp3 *= 244
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
		temp0++
		GetPaletteEntry(0, 5, temp1)
		GetPaletteEntry(1, 5, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_SonicSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 256
		temp1 /= object.value6
		temp2 *= 256
		temp2 /= object.value7
		temp3 *= 256
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_SonicSuperAltPal)
		temp0++
	loop
end function


function LZSetup_Function97
	temp0 = 0
	GetPaletteEntry(1, 13, temp1)
	SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
	temp0++
	GetPaletteEntry(1, 17, temp1)
	SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
	temp0++
	GetPaletteEntry(1, 18, temp1)
	SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
	temp0++
	GetPaletteEntry(1, 16, temp1)
	SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
	temp0++
	while temp0 < 24
		GetPaletteEntry(0, 13, temp1)
		GetPaletteEntry(1, 13, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_TailsSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 248
		temp1 /= object.value6
		temp2 *= 248
		temp2 /= object.value7
		temp3 *= 248
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
		temp0++
		GetPaletteEntry(0, 17, temp1)
		GetPaletteEntry(1, 17, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_TailsSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 256
		temp1 /= object.value6
		temp2 *= 256
		temp2 /= object.value7
		temp3 *= 256
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
		temp0++
		GetPaletteEntry(0, 18, temp1)
		GetPaletteEntry(1, 18, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_TailsSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 256
		temp1 /= object.value6
		temp2 *= 256
		temp2 /= object.value7
		temp3 *= 256
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
		temp0++
		GetPaletteEntry(0, 16, temp1)
		GetPaletteEntry(1, 16, temp2)
		CallFunction(LZSetup_Function95)
		GetTableValue(temp1, temp0, PlayerObject_TailsSuperPal)
		temp2 = temp1
		temp2 >>= 8
		temp2 &= 255
		temp3 = temp1
		temp3 &= 255
		temp1 >>= 16
		temp1 *= 256
		temp1 /= object.value6
		temp2 *= 256
		temp2 /= object.value7
		temp3 *= 256
		temp3 /= object.value8
		temp1 &= 240
		temp2 &= 240
		temp3 &= 240
		if temp1 > 224
			temp1 = 224
		end if
		if temp2 > 224
			temp2 = 224
		end if
		if temp3 > 224
			temp3 = 224
		end if
		temp1 <<= 16
		temp2 <<= 8
		temp1 += temp2
		temp1 += temp3
		SetTableValue(temp1, temp0, PlayerObject_TailsSuperAltPal)
		temp0++
	loop
end function


function LZSetup_Function98
	temp0 = 0
	GetPaletteEntry(1, 26, temp1)
	SetTableValue(temp1, temp0, PlayerObject_KnuxSuperAltPal)
	temp0++
	GetPaletteEntry(1, 27, temp1)
	SetTableValue(temp1, temp0, PlayerObject_KnuxSuperAltPal)
	temp0++
	GetPaletteEntry(1, 28, temp1)
	SetTableValue(temp1, temp0, PlayerObject_KnuxSuperAltPal)
	temp0++
	while temp0 < 30
		if temp0 < 18
			temp1 = temp0
			temp1 -= 3
			GetTableValue(temp2, temp1, PlayerObject_KnuxSuperAltPal)
			object.value9 = temp2
			object.value9 &= 0xE00000
			object.value10 = temp2
			object.value10 &= 0x00E000
			object.value11 = temp2
			object.value11 &= 0x0000E0
			object.value9 += 0x200000
			object.value10 += 0x002000
			object.value11 += 0x000020
			if object.value9 > 0xE00000
				object.value9 = 0xE00000
			end if
			if object.value10 > 0x00E000
				object.value10 = 0x00E000
			end if
			if object.value11 > 0x0000E0
				object.value11 = 0x0000E0
			end if
			temp2 = object.value9
			temp2 += object.value10
			temp2 += object.value11
		else
			temp1 = temp0
			temp1 /= 3 //which line of the palette are we on now?
			switch temp1
				case 6
					temp1 = temp0
					temp1 -= 6
					GetTableValue(temp2, temp1, PlayerObject_KnuxSuperAltPal)
					break
				case 7
					temp1 = temp0
					temp1 -= 12
					GetTableValue(temp2, temp1, PlayerObject_KnuxSuperAltPal)
					break
				case 8
					temp1 = temp0
					temp1 -= 18
					GetTableValue(temp2, temp1, PlayerObject_KnuxSuperAltPal)
					break
				case 9
					temp1 = temp0
					temp1 -= 24
					GetTableValue(temp2, temp1, PlayerObject_KnuxSuperAltPal)
					break
			end switch			
		end if
		SetTableValue(temp2, temp0, PlayerObject_KnuxSuperAltPal)
		temp0++
	loop
end function

function LZSetup_AmySuperPal
	temp0 = 0
	GetPaletteEntry(1, 48, temp1)
	SetTableValue(temp1, temp0, PlayerObject_AmySuperAltPal)
	temp0++
	GetPaletteEntry(1, 49, temp1)
	SetTableValue(temp1, temp0, PlayerObject_AmySuperAltPal)
	temp0++
	GetPaletteEntry(1, 50, temp1)
	SetTableValue(temp1, temp0, PlayerObject_AmySuperAltPal)
	temp0++
	GetPaletteEntry(1, 51, temp1)
	SetTableValue(temp1, temp0, PlayerObject_AmySuperAltPal)
	temp0++
	
	while temp0 < 32	
		if temp0 < 20
			temp1 = temp0
			temp1 -= 4
			GetTableValue(temp2, temp1, PlayerObject_AmySuperAltPal)
			object.value9 = temp2
			object.value9 &= 0xE00000
			object.value10 = temp2
			object.value10 &= 0x00E000
			object.value11 = temp2
			object.value11 &= 0x0000E0
			object.value9 += 0x200000
			object.value10 += 0x002000
			object.value11 += 0x000020
			if object.value9 > 0xE00000
				object.value9 = 0xE00000
			end if
			if object.value10 > 0x00E000
				object.value10 = 0x00E000
			end if
			if object.value11 > 0x0000E0
				object.value11 = 0x0000E0
			end if
			temp2 = object.value9
			temp2 += object.value10
			temp2 += object.value11
		else
			temp1 = temp0
			temp1 /= 4 //which line of the palette are we on now?
			switch temp1
				case 5
					temp1 = temp0
					temp1 -= 8
					GetTableValue(temp2, temp1, PlayerObject_AmySuperAltPal)
					break
				case 6
					temp1 = temp0
					temp1 -= 16
					GetTableValue(temp2, temp1, PlayerObject_AmySuperAltPal)
					break
				case 7
					temp1 = temp0
					temp1 -= 24
					GetTableValue(temp2, temp1, PlayerObject_AmySuperAltPal)
					break
			end switch			
		end if
		SetTableValue(temp2, temp0, PlayerObject_AmySuperAltPal)
		temp0++
	loop
end function


function LZSetup_YuriSuperPal
	temp0 = 0
	GetPaletteEntry(1, 86, temp1)
	SetTableValue(temp1, temp0, PlayerObject_YuriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 87, temp1)
	SetTableValue(temp1, temp0, PlayerObject_YuriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 88, temp1)
	SetTableValue(temp1, temp0, PlayerObject_YuriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 89, temp1)
	SetTableValue(temp1, temp0, PlayerObject_YuriSuperAltPal)
	temp0++
	while temp0 < 44	
		if temp0 < 28
			temp1 = temp0
			temp1 -= 4
			GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
			object.value9 = temp2
			object.value9 &= 0xE00000
			object.value10 = temp2
			object.value10 &= 0x00E000
			object.value11 = temp2
			object.value11 &= 0x0000E0
			object.value9 += 0x200000
			object.value10 += 0x002000
			object.value11 += 0x000020			
			if object.value9 > 0xE00000
				object.value9 = 0xE00000
			end if
			if object.value10 > 0x00E000
				object.value10 = 0x00E000
			end if
			if object.value11 > 0x0000E0
				object.value11 = 0x0000E0
			end if	
			temp2 = object.value9
			temp2 += object.value10
			temp2 += object.value11
		else
			temp1 = temp0
			temp1 /= 4 //which line of the palette are we on now?
			switch temp1
				case 8
					temp1 = temp0
					temp1 -= 8
					GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
					break
				case 9
					temp1 = temp0
					temp1 -= 16
					GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
					break
				case 10
					temp1 = temp0
					temp1 -= 24
					GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
					break
				case 11
					temp1 = temp0
					temp1 -= 32
					GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
					break
				case 12
					temp1 = temp0
					temp1 -= 40
					GetTableValue(temp2, temp1, PlayerObject_YuriSuperAltPal)
					break
			end switch			
		end if
		SetTableValue(temp2, temp0, PlayerObject_YuriSuperAltPal)
		temp0++
	loop
end function


function LZSetup_SayoriSuperPal
	temp0 = 0
	GetPaletteEntry(1, 59, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SayoriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 60, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SayoriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 61, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SayoriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 62, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SayoriSuperAltPal)
	temp0++
	GetPaletteEntry(1, 63, temp1)
	SetTableValue(temp1, temp0, PlayerObject_SayoriSuperAltPal)
	temp0++
	while temp0 < 55	
		if temp0 < 35
			temp1 = temp0
			temp1 -= 5
			GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
			object.value9 = temp2
			object.value9 &= 0xE00000
			object.value10 = temp2
			object.value10 &= 0x00E000
			object.value11 = temp2
			object.value11 &= 0x0000E0
			object.value9 += 0x200000
			object.value10 += 0x002000
			object.value11 += 0x000020
			if object.value9 > 0xE00000
				object.value9 = 0xE00000
			end if
			if object.value10 > 0x00E000
				object.value10 = 0x00E000
			end if
			if object.value11 > 0x0000E0
				object.value11 = 0x0000E0
			end if
			temp2 = object.value9
			temp2 += object.value10
			temp2 += object.value11
		else
			temp1 = temp0
			temp1 /= 5 //which line of the palette are we on now?
			switch temp1
				case 8
					temp1 = temp0
					temp1 -= 15
					GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
					break
				case 9
					temp1 = temp0
					temp1 -= 25
					GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
					break
				case 10
					temp1 = temp0
					temp1 -= 35
					GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
					break
				case 11
					temp1 = temp0
					temp1 -= 45
					GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
					break
				case 12
					temp1 = temp0
					temp1 -= 55
					GetTableValue(temp2, temp1, PlayerObject_SayoriSuperAltPal)
					break
			end switch			
		end if
		SetTableValue(temp2, temp0, PlayerObject_SayoriSuperAltPal)
		temp0++
	loop
end function


function LZSetup_NatsukiSuperPal
	temp0 = 0
	GetPaletteEntry(1, 55, temp1)
	SetTableValue(temp1, temp0, PlayerObject_NatsukiSuperAltPal)
	temp0++
	GetPaletteEntry(1, 56, temp1)
	SetTableValue(temp1, temp0, PlayerObject_NatsukiSuperAltPal)
	temp0++
	GetPaletteEntry(1, 57, temp1)
	SetTableValue(temp1, temp0, PlayerObject_NatsukiSuperAltPal)
	temp0++
	GetPaletteEntry(1, 58, temp1)
	SetTableValue(temp1, temp0, PlayerObject_NatsukiSuperAltPal)
	temp0++

	while temp0 < 44	
		if temp0 < 28
			temp1 = temp0
			temp1 -= 4
			GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
			object.value9 = temp2
			object.value9 &= 0xE00000
			object.value10 = temp2
			object.value10 &= 0x00E000
			object.value11 = temp2
			object.value11 &= 0x0000E0
			object.value9 += 0x200000
			object.value10 += 0x002000
			object.value11 += 0x000020
			if object.value9 > 0xE00000
				object.value9 = 0xE00000
			end if
			if object.value10 > 0x00E000
				object.value10 = 0x00E000
			end if
			if object.value11 > 0x0000E0
				object.value11 = 0x0000E0
			end if
			temp2 = object.value9
			temp2 += object.value10
			temp2 += object.value11
		else
			temp1 = temp0
			temp1 /= 4 //which line of the palette are we on now?
			switch temp1
				case 8
					temp1 = temp0
					temp1 -= 8
					GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
					break
				case 9
					temp1 = temp0
					temp1 -= 16
					GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
					break
				case 10
					temp1 = temp0
					temp1 -= 24
					GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
					break
				case 11
					temp1 = temp0
					temp1 -= 32
					GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
					break
				case 12
					temp1 = temp0
					temp1 -= 40
					GetTableValue(temp2, temp1, PlayerObject_NatsukiSuperAltPal)
					break
			end switch			
		end if
		SetTableValue(temp2, temp0, PlayerObject_NatsukiSuperAltPal)
		temp0++
	loop
end function


function LZSetup_Function99
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("Labyrinth_F.ogg", 0, 0x107D2, 0x1F40)
			break
		case 2
			SetMusicTrack("Labyrinth_F.ogg", 0, 0x107D2)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("Labyrinth_F.ogg", 0, 0x107D2)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function LZSetup_Function100
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("Labyrinth.ogg", 0, 0x149DC, 0x30D4)
			break
		case 2
			SetMusicTrack("Labyrinth.ogg", 0, 0x149DC)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("Labyrinth.ogg", 0, 0x149DC)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


function LZSetup_Function101
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("ScrapBrain_F.ogg", 0, 1, 0x1F40)
			break
		case 2
			SetMusicTrack("ScrapBrain_F.ogg", 0, 1)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("ScrapBrain_F.ogg", 0, 1)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function LZSetup_Function102
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("ScrapBrain.ogg", 0, 1, 0x30D4)
			break
		case 2
			SetMusicTrack("ScrapBrain.ogg", 0, 1)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("ScrapBrain.ogg", 0, 1)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	object.value0++
	if object.value0 > 1
		tileLayer[0].deformationOffsetW++
		tileLayer[1].deformationOffsetW++
		object.value0 = 0
	end if
	object.value1++
	if object.value1 == 3
		object.value1 = 0
		RotatePalette(0, 171, 174, 0)
		RotatePalette(1, 171, 174, 0)
	end if
	if object.value2 > 0
		object.value2--
	else
		object.value3++
		object.value3 %= 3
		GetTableValue(object.value2, object.value3, LZSetup_table25)
		RotatePalette(0, 187, 189, LZSetup_value30)
		RotatePalette(1, 187, 189, LZSetup_value30)
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp1 = object[currentPlayer].xpos
		temp1 >>= 16
		temp2 = object[currentPlayer].ypos
		temp2 >>= 16
		temp2 += object[currentPlayer].collisionBottom
		temp2--
		Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_INDEX)
		CheckEqual(temp0, 71)
		temp3 = checkResult
		CheckEqual(temp0, 72)
		temp3 |= checkResult
		if temp3 == 1
			CheckEqual(object[currentPlayer].state, PlayerObject_KnuxGlideLeft)
			temp3 = checkResult
			CheckEqual(object[currentPlayer].state, PlayerObject_KnuxGlideRight)
			temp3 |= checkResult
			CheckEqual(object[currentPlayer].state, PlayerObject_KnuxWallClimb)
			temp3 |= checkResult
			CheckEqual(object[currentPlayer].state, PlayerObject_KnuxLedgePullUp)
			temp3 |= checkResult
			if temp3 == 1
				if object[currentPlayer].state == PlayerObject_KnuxGlideLeft
					FlipSign(object[currentPlayer].xvel)
					FlipSign(object[currentPlayer].speed)
				end if
				object[currentPlayer].state = PlayerObject_KnuxGlideDrop
				object[currentPlayer].animation = ANI_GLIDING_DROP
			end if
		end if
		if object[currentPlayer].state != PlayerObject_HandleMonikaTeleport			
			if object[currentPlayer].gravity == GRAVITY_GROUND
				Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
				if temp0 == 1
					object[currentPlayer].state = PlayerObject_WaterSlide
					Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_DIRECTION)
					switch temp0
					case 0
					case 2
						object[currentPlayer].direction = FLIP_X
						break
					case 1
					case 3
						object[currentPlayer].direction = FLIP_NONE
						break
					end switch
				end if
			end if
		end if
	next
	if object[0].state == PlayerObject_WaterSlide
		if object.value4 == 0
			if object.value5 == 0
				PlaySfx(SfxName[Waterfall], 0)
				StopSfx(SfxName[Waterfall Loop])
				object.value5 = 1
			else
				StopSfx(SfxName[Waterfall])
				PlaySfx(SfxName[Waterfall Loop], 0)
			end if
		end if
		object.value4++
		object.value4 &= 63
	else
		if object.value4 != 0
			object.value4++
			object.value4 &= 63
		else
			object.value4 = 0
			object.value5 = 0
		end if
	end if
	if LZSetup_value29 > 0
		LZSetup_value29--
	end if
end event


event ObjectDraw
	temp0 = stage.waterLevel
	temp0 -= screen.yoffset
	if temp0 < 0
		temp0 = 0
	end if
	if temp0 > screen.ysize
		temp0 = screen.ysize
	end if
	SetActivePalette(0, 0, temp0)
	if LZSetup_value29 > 0
		SetActivePalette(2, temp0, screen.ysize)
	else
		SetActivePalette(1, temp0, screen.ysize)
	end if
end event


event ObjectStartup
	LZSetup_value30 = 0
	if stage.actNum < 4
		SetMusicTrack("Labyrinth.ogg", 0, 0x149DC)
		SpeedUpMusic = LZSetup_Function99
		SlowDownMusic = LZSetup_Function100
	else
		SetMusicTrack("ScrapBrain.ogg", 0, 1)
		SpeedUpMusic = LZSetup_Function101
		SlowDownMusic = LZSetup_Function102
	end if

	animalType1 = TypeName[Pecky]
	animalType2 = TypeName[Rocky]
	object[10].type = TypeName[LZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	object[10].drawOrder = 0
	GetTableValue(object[10].value2, 0, LZSetup_table25)
	arrayPos0 = 0
	CallFunction(LZSetup_Function93)
	arrayPos0 = 128
	CallFunction(LZSetup_Function93)
	arrayPos0 = 160
	CallFunction(LZSetup_Function94)
	arrayPos0 = 256
	while arrayPos0 < 576
		arrayPos1 = arrayPos0
		arrayPos1 -= 256
		stage[arrayPos0].deformationData1 = stage[arrayPos1].deformationData1
		arrayPos0++
	loop
	SetLayerDeformation(3, 128, 4, 0, 0, 0)
	if stage.actNum < 4
		LoadPalette("LZ_WaterPal.act", 1, 0, 0, 256)
	else
		LoadPalette("SBZ3_Pal.act", 0, 128, 128, 192)
		LoadPalette("SBZ3_WaterPal.act", 1, 0, 0, 256)
	end if
	CallFunction(LZSetup_Function96)
	CallFunction(LZSetup_Function97)
	CallFunction(LZSetup_Function98)
	CallFunction(LZSetup_AmySuperPal)
	CallFunction(LZSetup_NatsukiSuperPal)
	CallFunction(LZSetup_YuriSuperPal)
	CallFunction(LZSetup_SayoriSuperPal)
	LoadPalette("ElectricFlash.act", 2, 0, 0, 256)
	LZSetup_value29 = 0
	if options.attractMode == 1
		if credits.screen > 0
			PlayerObject_ReplayTable = LZSetup_table1
			PlayerObject_ReplaySize = 76
			PlayerObject_ReplayLength = 540
		end if
		CallFunction(PlayerObject_InitReplay)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
